package com.dfxs.thread;

import java.util.concurrent.CountDownLatch;

/**
 * @author zhangdongsheng
 * @version 1.0
 * @describe
 * @date 2022/2/17 21:20
 */
public class PrintThreadNum {
    private CountDownLatch second = new CountDownLatch(1);
    private CountDownLatch third = new CountDownLatch(1);

    public PrintThreadNum() {

    }

    public void first(Runnable printFirst) throws InterruptedException {

        // printFirst.run() outputs "first". Do not change or remove this line.
        printFirst.run();
        second.countDown();
    }

    public void second(Runnable printSecond) throws InterruptedException {

        second.await();
        // printSecond.run() outputs "second". Do not change or remove this line.
        printSecond.run();
        third.countDown();
    }

    public void third(Runnable printThird) throws InterruptedException {

        third.await();
        // printThird.run() outputs "third". Do not change or remove this line.
        printThird.run();
    }

    public static void main(String[] args) throws InterruptedException {
        print();
    }

    public static void print() throws InterruptedException {
        Thread thread1 = new Thread();
        Thread thread2 = new Thread();
        Thread thread3 = new Thread();

        PrintThreadNum printThreadNum = new PrintThreadNum();
        printThreadNum.first(thread1);
        printThreadNum.second(thread2);
        printThreadNum.third(thread3);
    }
}
